package com.zb.order.controller;


import com.zb.annotation.SystemLog;
import com.zb.constant.OperationLogModuleType;
import com.zb.constant.OperationLogType;
import com.zb.entity.SelectVo;
import com.zb.result.Result;
import com.zb.service.ZjWorkWarningService;
import com.zb.utils.TokenUtil;
import com.zb.vo.WorkWarningVo;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import javax.servlet.http.HttpServletRequest;
import javax.validation.Valid;
import java.util.List;

/**
 * <p>
 * 工单预警表 前端控制器
 * </p>
 *
 * @author WEN
 * @since 2023-09-13
 */
@Api(tags = "工单预警类接口")
@RestController
@RequestMapping("/work/warning")
public class ZjWorkWarningController {
    @Resource
    private ZjWorkWarningService workWarningService;

    @SystemLog(moduleType = OperationLogModuleType.WORK_ORDER_TYPE, type = OperationLogType.INSERT_UPDATE, remark = "工单管理-工单设置-工单策略-工单预警 - 新增或修改工单预警")
    @ApiOperation("新增或修改工单预警")
    @PostMapping("/save")
    public Result save(HttpServletRequest request, @RequestBody @Valid WorkWarningVo workWarningVo) {
        Long custAccId = TokenUtil.getcustAccIdByToken(request);
        workWarningService.save(custAccId, workWarningVo);
        return Result.success(null == workWarningVo.getId()? "新增工单预警成功" : "修改工单预警成功");
    }

    @ApiOperation("获取工单预警列表")
    @PostMapping("/getList")
    public Result getList(HttpServletRequest request, @RequestBody SelectVo selectVo) {
        Long custAccId = TokenUtil.getcustAccIdByToken(request);
        return Result.success("获取工单预警列表成功").data(workWarningService.getList(custAccId, selectVo));
    }

    @ApiOperation("根据预警ID获取工单预警详情")
    @GetMapping("/getDetail/{id}")
    public Result getDetail(@PathVariable @ApiParam(value = "预警ID", required = true) Long id) {
        return Result.success("获取工单预警详情成功").data("row", workWarningService.getDetail(id));
    }

    @SystemLog(moduleType = OperationLogModuleType.WORK_ORDER_TYPE, type = OperationLogType.UPDATE, remark = "工单管理-工单设置-工单策略-工单预警 - 根据预警ID批量启用或禁用预警")
    @ApiOperation("根据预警ID批量启用或禁用预警")
    @PostMapping("/disable")
    public Result disable(@RequestParam @ApiParam(value = "预警状态：false-启用，true-禁用", required = true, example = "false") boolean status,
                          @RequestBody @ApiParam(value = "预警ID集合", required = true) List<Long> idList) {
        workWarningService.updateDisabledBatchById(idList, status);
        return Result.success(status? "禁用预警成功" : "启用预警成功");
    }

    @SystemLog(moduleType = OperationLogModuleType.WORK_ORDER_TYPE, type = OperationLogType.DELETE, remark = "工单管理-工单设置-工单策略-工单预警 - 根据预警ID批量删除预警")
    @ApiOperation("根据预警ID批量删除预警")
    @DeleteMapping("/")
    public Result delete(@RequestBody @ApiParam(value = "预警ID集合", required = true) List<Long> idList) {
        workWarningService.deleteBatchById(idList);
        return Result.success("删除预警成功");
    }

}
